package com.baidu.st.fe.spllot.detect;

import java.io.File;
import java.util.Iterator;
import java.util.Map;

import com.baidu.st.fe.spllot.load.CodeLoader;
import com.baidu.st.fe.spllot.load.FileCodeLoader;
import com.baidu.st.fe.spllot.parse.BaseStringJavaParse;

public class BaseStringJavaDetect {
	public static void detect(){
		
		CodeLoader fcl = new FileCodeLoader(new File("E:\\t.java"), "gb2312");

		Map<Integer, String> alines = BaseStringJavaParse.parseJavaLanguage(fcl);
		Map<Integer, String> lines = BaseStringJavaParse.removeSpace(alines);

		Iterator<Integer> iterator = lines.keySet().iterator();
		String code = "";
		while (iterator.hasNext()) {
			int key = iterator.next();
			System.out.print(key);
			code+= lines.get(key);
			System.out.print(lines.get(key));
		}
		
		int position;

		JSuffixTree app = new JSuffixTree();
		/* Create the suffix tree */
		String str = code;

		// abba#xbac!bbxb*acyde@a00
		SUFFIX_TREE tree = app.ST_CreateTree(str, str.length());

		/* Print the suffix tree. */
		app.ST_PrintTree(tree);

		//String toFind = "u";
		//position = app.ST_FindSubstring(tree, toFind, toFind.length());
		//System.out.println("the position of " + toFind + " is " + position);	
		
	}

	public static void main(String args[]){
		detect();
	}
}
